<%@page import="java.util.List"%>
<%@page import="com.jfinal.plugin.activerecord.Page"%>
<%@page import="com.hongye.app.model.GoodsCategroyModel"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false"
    pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html class="fixed">

	<head>

		<!-- Basic -->
		<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

		<meta name="keywords" content="HTML5 Admin Template" />
		<meta name="description" content="Porto Admin - Responsive HTML5 Template">
		<meta name="author" content="okler.net">

		<!-- Mobile Metas -->
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

		<!-- Web Fonts  -->


		<!-- Vendor CSS -->
		<link rel="stylesheet" href="../admin/css/bootstrap.css" />

		<link rel="stylesheet" href="../admin/css/font-awesome/css/font-awesome.css" />
        <link rel="stylesheet" href="../admin/css/select2.css" />
		<!-- Theme CSS -->
		<link rel="stylesheet" href="../admin/css/theme.css" />

		<!-- Skin CSS -->
		<link rel="stylesheet" href="../admin/css/default.css" />

		<!-- Theme Custom CSS -->

		<!-- Theme Custom ../admin/css -->

		<script src="../admin/js/modernizr.js"></script>
	</head>
	
	<body>
		<section role="main" class="content-body" style="margin-top: 50px; height:1000px;">

			<!-- start: page -->
			<section class="panel">
				<header class="panel-heading">
									<h2 class="panel-title">商品分类管理</h2>
								</header>
								
								<div class="panel-body" >
									
									<div class="row">
										<div class="col-sm-6">
											<div class="mb-md">
												<button id="addToTable" class="btn btn-primary" onclick="addgroy();">添加分类 </button>
											</div>
										</div>
									</div>
									<div id="addgroy" style="display:none">添加类别<br>
										类别名称<input id="name" type="text" name="name" placeholder="男装" />
										父节点<input id="pid" type="text" name="pid" placeholder="105" />
										<a class="btn btn-facebook mb-md ml-xs mr-xs" onclick="agreeadd();">确定提交 </a>
                       					<a class="btn btn-facebook mb-md ml-xs mr-xs" onclick="hid();">取消</a>
									</div>
									
									<button type="button" class="btn btn-success">一级分类</button>
									<div id="treeDragDrop" style="height:280px;width:100%;background:#f3f9f1;" >
									<p>
										<%List<GoodsCategroyModel> goodscategroy=(List)request.getAttribute("goodscategroy");
											for(int i=1;i<=goodscategroy.size();i++){
												GoodsCategroyModel gam1=goodscategroy.get(i-1);
												if(gam1.getInt("pid")<100){
											%>
										<ul class="list-inline">
											<li class="col-xs-6 col-sm-3" data-jstree='{ "selected" : true }'>
												<a href="../goods/get2Categroy?pid=<%=gam1.get("pid")%>" > <%=gam1.get("pid") %>： <%=gam1.get("c_name") %></a>
												<a href="../goods/categroydetail?pid=<%=gam1.get("pid")%>" class="on-default edit-row" ><i class="fa fa-pencil"></i></a>
											</li>
										</ul>
									<%} }%>
									</div>
									<button type="button" class="btn btn-warning">二级分类</button><p>
									<div id="treeDragDrop" style="height:360px;width:100%;background:#f3f9f1;" >
										<%List<GoodsCategroyModel> categroy=(List)request.getAttribute("list");
										if(categroy.size()!=0){
											for(int k=1;k<=categroy.size();k++){
												GoodsCategroyModel gam2=categroy.get(k-1);
											%>
										<ul class="list-inline">
											<li class="col-xs-6 col-sm-3" data-jstree='{ "selected" : true }'>
												<a href="#"><%=gam2.get("pid") %>：<%=gam2.get("c_name") %></a>
												<a href="../goods/categroydetail?pid=<%=gam2.get("pid")%>" class="on-default edit-row" ><i class="fa fa-pencil"></i></a>
											</li>
										</ul>
										<%}}%>
									</div>
								</div>
							
		</section>
		<!-- Specific Page Vendor -->
		<!-- Vendor -->
		<script src="../admin/js/jquery.js"></script>
		<script type="text/javascript">
			//显示添加div
			function addgroy(){
				$("#addgroy").css('display','block'); 
			}
			//隐藏添加div
			function hid(){
				$("#addgroy").css('display','none'); 
			}
			//添加类别
			function agreeadd(){				
				var name = $("#name").val();
				var pid = $("#pid").val();
				$.get('../goods/addCategroy?name='+name+'&pid='+pid,function(data){
					
					if(data=='suc'){
						location.href='../goods/goodsCategroyView';
					}else if(data=='fal'){
						alert('提交失败!');
					}else if(data=='re'){
						alert('数据重复！');
					}
				});
			}
			
		</script>
		</section>
		
	</body>

</html>